package com.xdog.web3.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.xdog.web3.config.Web3ConfigService;
import com.xdog.web3.domain.token.*;
import com.xdog.web3.service.IWeb3TokenService;
import com.xdog.web3.utils.Web3ApiUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Web3代币服务实现类
 */
@Slf4j
@Service
public class Web3TokenServiceImpl implements IWeb3TokenService {

    @Resource
    private Web3ConfigService web3ConfigService;

    @Override
    public JSONObject searchTokens(TokenSearchQuery query) {
        String requestPath = "/api/v6/dex/market/token/search";

        Map<String, String> params = new HashMap<>();
        params.put("chains", query.getChains());
        params.put("search", query.getSearch());

        return Web3ApiUtil.get(requestPath, params);
    }

    @Override
    public JSONObject getTokenBasicInfo(List<TokenBasicInfoRequest> requests) {
        String requestPath = "/api/v6/dex/market/token/basic-info";
        return Web3ApiUtil.post(requestPath, requests);
    }

    @Override
    public JSONObject getTokenPriceInfo(List<TokenPriceInfoRequest> requests) {
        String requestPath = "/api/v6/dex/market/price-info";
        return Web3ApiUtil.post(requestPath, requests);
    }

    @Override
    public JSONObject getTokenTopList(TokenTopListQuery query) {
        String requestPath = "/api/v6/dex/market/token/toplist";

        Map<String, String> params = new HashMap<>();
        params.put("chains", query.getChains());
        params.put("sortBy", query.getSortBy());
        params.put("timeFrame", query.getTimeFrame());

        return Web3ApiUtil.get(requestPath, params);
    }

    @Override
    public JSONObject getTokenHolders(TokenHolderQuery query) {
        String requestPath = "/api/v6/dex/market/token/holder";

        Map<String, String> params = new HashMap<>();
        params.put("chainIndex", query.getChainIndex());
        params.put("tokenContractAddress", query.getTokenContractAddress());

        return Web3ApiUtil.get(requestPath, params);
    }
}